package cn.com.bluemoon.daps.model.controller;

import cn.com.bluemoon.daps.common.datascope.BmPermission;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.model.dto.ModelMetadataMappingDto;
import cn.com.bluemoon.daps.model.service.DapModelMetadataMappingService;
import cn.com.bluemoon.daps.model.vo.ModelMetadataMappingPageVo;
import cn.com.bluemoon.daps.model.vo.ModelMetadataMappingVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 模型和元数据映射表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2022-11-02
 */
@RequestMapping("/api/modelMetadataMapping")
@Api(value = "模型和元数据系统管理服务", tags = "模型和元数据系统管理服务")
@Validated
@RestController
@Slf4j
public class DapModelMetadataMappingController {

    @Autowired
    private DapModelMetadataMappingService dapModelMetadataMappingService;

    @BmPermission(name = "获取模型和元数据系统管理列表",value = "model:modelMetadataMapping:list")
    @ApiOperation("获取数据模型管理列表")
    @PostMapping("/list")
    public ResultBean<IPage<ModelMetadataMappingDto>> list(@RequestBody ModelMetadataMappingPageVo request) {
        IPage<ModelMetadataMappingDto> modelMetadataMappingVOIPage = dapModelMetadataMappingService.listByPage(request);
        return ResultBean.ok(modelMetadataMappingVOIPage);
    }

    @BmPermission(name = "模型和元数据系统关系新增",value = "model:modelMetadataMapping:add")
    @ApiOperation("模型和元数据系统关系新增")
    @PostMapping("/add")
    public ResultBean<Boolean> add(@RequestBody ModelMetadataMappingVo request){
        Boolean isSuccess = dapModelMetadataMappingService.saveModelMetadataMapping(request);
        return  ResultBean.ok(isSuccess);
    }

    @BmPermission(name = "模型和元数据系统关系修改",value = "model:modelMetadataMapping:edit")
    @ApiOperation("模型和元数据系统关系修改")
    @PostMapping("/edit")
    public ResultBean<Boolean> edit(@RequestBody ModelMetadataMappingVo request){
        Boolean isSuccess = dapModelMetadataMappingService.saveModelMetadataMapping(request);
        return ResultBean.ok(isSuccess);
    }

    @ApiOperation("模型和元数据系统关系删除")
    @BmPermission(name = "模型和元数据系统关系删除",value = "model:modelMetadataMapping:delete")
    @GetMapping("/delete")
    public ResultBean<Boolean> delete(@RequestParam("id") Long id){
        boolean isSuccess = dapModelMetadataMappingService.removeById(id);
        return ResultBean.ok(isSuccess);
    }

}
